﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.GroupCommands.CUIPickLevelGroupCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.GroupCommands.Resources;
using EngineeringInternalExtension;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.GroupCommands;

internal class CUIPickLevelGroupCmd : TxRibbonGroupButtonCommand
{
  public CUIPickLevelGroupCmd() => ((TxButtonCommand) this).SetStayEnabledInSemiModalMode(true);

  public virtual string Category => GroupCommandsStringTable.PICK_LEVEL_GROUP_CMD_CATEGORY;

  public virtual string Description => GroupCommandsStringTable.PICK_LEVEL_GROUP_CMD_DESCRIPTION;

  public virtual string Name => GroupCommandsStringTable.PICK_LEVEL_GROUP_CMD_NAME;

  public virtual string Tooltip => GroupCommandsStringTable.PICK_LEVEL_GROUP_CMD_TOOLTIP;

  public virtual string Bitmap => "GroupCommands.Resources.PickLevelSmall.bmp";

  public virtual string LargeBitmap => "GroupCommands.Resources.PickLevelBig.png";

  private TxPickLevelEx GetNextPickLevel(TxPickLevelEx pickLevel)
  {
    TxPickLevelEx nextPickLevel = (TxPickLevelEx) 1;
    if (pickLevel == 1)
      nextPickLevel = (TxPickLevelEx) 2;
    else if (pickLevel == 5)
      nextPickLevel = (TxPickLevelEx) 6;
    else if (pickLevel == 6)
      nextPickLevel = (TxPickLevelEx) 1;
    else if (pickLevel == 2)
      nextPickLevel = (TxPickLevelEx) 4;
    else if (pickLevel == 4)
      nextPickLevel = (TxPickLevelEx) 5;
    else if (pickLevel == 3)
      nextPickLevel = (TxPickLevelEx) 4;
    return nextPickLevel;
  }

  private string GetPickLevelCommandId(TxPickLevelEx pickLevel)
  {
    string pickLevelCommandId = "";
    if (pickLevel == 1)
      pickLevelCommandId = "GraphicViewer.ComponentPickLevel";
    else if (pickLevel == 5)
      pickLevelCommandId = "GraphicViewer.EdgePickLevel";
    else if (pickLevel == 6)
      pickLevelCommandId = "GraphicViewer.EndItemPickLevel";
    else if (pickLevel == 2)
      pickLevelCommandId = "GraphicViewer.EntityPickLevel";
    else if (pickLevel == 4)
      pickLevelCommandId = "GraphicViewer.FacePickLevel";
    else if (pickLevel == 3)
      pickLevelCommandId = "GraphicViewer.GroupPickLevel";
    return pickLevelCommandId;
  }

  private TxPickLevelEx GetNextAvailablePickLevelCommandId()
  {
    TxPickLevelEx nextPickLevel = this.GetNextPickLevel(TxGraphicViewerEx.PickLevel);
    string pickLevelCommandId1 = this.GetPickLevelCommandId(nextPickLevel);
    string pickLevelCommandId2;
    for (bool flag = TxApplication.CommandsManager.IsCommandConnected(pickLevelCommandId1) & TxApplication.CommandsManager.IsCommandEnabled(pickLevelCommandId1, false); !flag; flag = TxApplication.CommandsManager.IsCommandConnected(pickLevelCommandId2) & TxApplication.CommandsManager.IsCommandEnabled(pickLevelCommandId2, false))
    {
      nextPickLevel = this.GetNextPickLevel(nextPickLevel);
      pickLevelCommandId2 = this.GetPickLevelCommandId(nextPickLevel);
    }
    return nextPickLevel;
  }

  public virtual void Execute(object cmdParams)
  {
    TxGraphicViewerEx.PickLevel = this.GetNextAvailablePickLevelCommandId();
  }
}
